package com.chun.api;

import java.io.IOException;
import java.util.Map;

import org.springframework.util.StringUtils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class UtilJson {
	public static ObjectMapper JSON_MAPPER = new ObjectMapper();
	public static Map<String, Object> toMap(String paramsJson) {
		
		// json to map
		return null;
	}

	public static <T> T convertValue(Object value,Class<T> clazz){
		if (StringUtils.isEmpty(value) ) {
			return null;
		}
		try {
			if (value instanceof String) {
				value = JSON_MAPPER.readTree((String) value);
				return JSON_MAPPER.convertValue(value,clazz);
			}
		} catch (Exception e) {
			throw new IllegalArgumentException(e);
		}
		return null;
	}

	public static String writeValueAsString(Object result) throws IOException {
		
		return JSON_MAPPER.writeValueAsString(result);
	}
}
